package lianxi;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

public class _13_ {

	public static void main(String[] args) {
		HashMap<String, Integer> m = new HashMap<String, Integer>();

		try (FileInputStream fis = new FileInputStream("./src/lianxi/input.txt");
				InputStreamReader isr = new InputStreamReader(fis);
				BufferedReader fr = new BufferedReader(isr);) {
			String s = null;
			while ((s = fr.readLine()) != null) {
				if (m.containsKey(s)) {
					m.put(s, m.get(s) + 1);
				} else {
					m.put(s, 1);
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		Set<Entry<String, Integer>> set = m.entrySet();
		List<Entry<String, Integer>> list = new ArrayList<Entry<String, Integer>>(set);

		Collections.sort(list, (x, y) -> {
			if (y.getValue() == x.getValue()) {
				return x.getKey().compareTo(y.getKey());
			}
			return y.getValue() - x.getValue();
		});

		System.out.println(list);
	}
}
